| Conditions | 6 |
| Paths | 5 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | |||
| 12 | export function replaceLineEndings (txt, CRLF) { |
||
| 13 | // replaces line endings within txt, with CRLF if CRLF is true, otherwise just LF |
||
| 14 | if (CRLF === true) { |
||
| 15 | // NB can't do the replacement of '\n' with '\r\n' using regex due to javascript limitations |
||
| 16 | let p = 0 // current position in the string |
||
| 17 | let x = 0 // location of '\n' in the string |
||
| 18 | let t = '' // output string |
||
| 19 | while (true) { |
||
| 20 | x = txt.indexOf('\n', p) |
||
| 21 | if (x === -1) { |
||
| 22 | // we've not got any more '\n' in the string so complete and exit |
||
| 23 | t = t + txt.substr(p) |
||
| 24 | return t |
||
| 25 | } else if (x === 0 || txt.substr(x - 1, 1) !== '\r') { |
||
| 26 | t = t + txt.substring(p, x) + '\r\n' |
||
| 27 | p = x + 1 |
||
| 28 | } else { |
||
| 29 | t = t + txt.substring(p, x + 1) |
||
| 30 | p = x + 1 |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } else { |
||
| 34 | return txt.replace(/(\r\n)/g, '\n') |
||
| 35 | } |
||
| 36 | } |
||
| 37 |